package filter;

import java.io.IOException;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import bean.Goods;
import dao.ListGoods;

/**
 * Servlet Filter implementation class ListView
 * 每次进入list.jsp页面都查询出最新的20条记录，并给页面传递页码总页数等信息
 */
public class ListView implements Filter {

    /**
     * Default constructor. 
     */
    public ListView() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		// place your code here
		
		/**
		 * 获取数据库Goods最后二十条纪录
		 */
		List<Goods> list;
		list = ListGoods.getListGoods("select * from goods where goods_state=1 order by goods_id desc limit 20");//执行具体获取方法
		request.setAttribute("tenten", list);//将结果放入request
		request.setAttribute("page", 1);
		request.setAttribute("goodsname", "");
		request.setAttribute("goodssort", "");
		request.setAttribute("lowprice", "");
		request.setAttribute("highprice", "");
		// pass the request along the filter chain
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	@Override
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
